package com.dong.controller.admin;

import com.dong.config.TitleConfig;
import com.dong.exception.Result;
import com.dong.service.CommentService;
import com.dong.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private TitleConfig titleConfig;

    @GetMapping("list")
    public String list(PageResult pageResult, @RequestParam(value = "name",required = false,defaultValue = " ") String name, Model model){
        model.addAttribute("title",titleConfig.getCommentTitle());
        model.addAttribute("name",name );
        model.addAttribute("pageResult",commentService.selectPage(pageResult,name));
        return "admin/comment/list";
    }

    @DeleteMapping("delete")
    @ResponseBody
    public Result<Boolean> delete(@RequestParam(value = "id",required = true)Integer id){
        commentService.deleteComment(id);
        return Result.success(true);
    }
}
